package com.example.onlineshop.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

//{ success: boolean, data: any, message?: string }
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppResult<T> implements Serializable {
    private boolean success;
    private T data;
    private String message;

    public AppResult(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    public static <T> AppResult<T> appResultSuccess(T data) {
        AppResult<T> result = new AppResult<T>(true, data);
        return result;
    }

    public static <T> AppResult<T> appResultFailed(T data) {
        AppResult<T> result = new AppResult<T>(false, null, "操作失败");
        return result;
    }
}
